﻿/*
 *  Copyright (c) 2012 Brandon Ellenberger
 *
 *  This file is part of OpSatPlan.
 *
 *  OpSatPlan is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  OpSatPlan is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with OpSatPlan.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OpSatPlan
{
    public class ValuedAtomicFormula
    {
        private bool mValue;
        private AtomicFormula mAtomicFormula;
        private int? mHashCode;
        public ValuedAtomicFormula(AtomicFormula af, bool value)
        {
            this.mValue = value;
            this.mAtomicFormula = af;
            this.mHashCode = null;
        }
        public bool Value
        {
            get
            {
                return this.mValue;
            }
        }
        public AtomicFormula AtomicFormula
        {
            get
            {
                return this.mAtomicFormula;
            }
        }
        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;
            else if (obj.GetType() == typeof(ValuedAtomicFormula))
                return this == (ValuedAtomicFormula)obj;
            else
                return false;
        }

        public static bool operator ==(ValuedAtomicFormula x, ValuedAtomicFormula y)
        {
            if (System.Object.ReferenceEquals(x, y))
                return true;
            else if ((object)x == null || (object)y == null)
                return false;
            else
                return x.GetHashCode() == y.GetHashCode();

        }

        public static bool operator !=(ValuedAtomicFormula x, ValuedAtomicFormula y)
        {
            return !(x == y);
        }

        public override int GetHashCode()
        {
            if (this.mHashCode == null)
            {
                int result = 17;
                result = result * 37 + this.mAtomicFormula.GetHashCode();
                result = result * 37 + this.mValue.GetHashCode();
                this.mHashCode = result;
            }
            return this.mHashCode.Value;
        }
        public override string ToString()
        {
            if (Value)
                return this.mAtomicFormula.ToString();
            else
                return "~" + this.mAtomicFormula.ToString();
        }
    }
}
